#!usr/bin/python
# -*= coding: UTF-8 -*-
'''
代理
1.参数是一个字典{'类型': '代理ip:端口号'}
proxy_support = urllib.request.ProxyHandler({})

2.定制、创建一个opener
opener = urllib.request.build_opener(proxy_support)

3.调用opener
opener.open(url)
'''
import urllib.request
import random

url = 'http://www.whatismyip.com.tw/'

iplist = ['119.6.144.73:81', '183.203.208.166:8118', '111.1.32.28:81']

#proxy_support = urllib.request.ProxyHandler({'http': '119.6.144.73:81'})
proxy_support = urllib.request.ProxyHandler({'http': random.choice(iplist)})

operer = urllib.request.build_opener(proxy_support)
operer.addheaders = ['User-Agent', 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.116 Safari/537.36']

urllib.request.install_opener(operer)

resopnse = urllib.request.urlopen(url)
html = resopnse.read().decode('utf-8')

print(html)









